/**
 * Created by no1 on 2014/12/11.
 */

var fs = require('fs');
var C = require('./config');
var api = require('./servers/apiHTTP');

api.listen(C.apiPort);
console.log('API server is listening on ' + C.apiPort + ' port.');

var server = require('sc-filter').createServer();

if (C.wordFilter.unix_socket) { // Unix Socket 方式
    if (fs.existsSync(C.wordFilter.unix_socket)) {
        fs.unlinkSync(C.wordFilter.unix_socket);
    }
    server.set('connectStr', C.wordFilter.unix_socket);
} else { // TCP 方式
    server.set('connectStr', C.wordFilter.port);
}

server.loadDict(function loaded() {
    server.listen(server.get('connectStr'), function () {
        console.log('Dict server is listening on ' + server.get('connectStr'));
    });
});

